package com.ejd.web.vo.manage.shoes;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;

import net.sf.cglib.beans.BeanCopier;

import com.ejd.service.IGoodsService;
import com.ejd.utils.SpringFacesUtil;
import com.ejd.web.bo.impl.Customer;
import com.ejd.web.bo.impl.Goods;
import com.ejd.web.bo.impl.GoodsProperties;
import com.ejd.web.constant.EjdConstants;
import com.ejd.web.constant.ManageBeanConstants;
import com.ejd.web.constant.SpringBeanConstants;
import com.ejd.web.vo.common.CustomerVo;
import com.ejd.web.vo.common.GoodsPropertiesVo;
import com.ejd.web.vo.common.GoodsVo;

@ManagedBean(name="addCartGoodsPropertiesPage")
@SessionScoped
public class AddCartGoodsPropertiesPageBean implements Serializable {

	private static final long serialVersionUID = 5054087821033164847L;
	private GoodsVo shoes = new GoodsVo();
	private List<GoodsPropertiesVo> shoesProperties = new ArrayList<GoodsPropertiesVo>();
	private boolean hasProperties;
	//end
	public AddCartGoodsPropertiesPageBean(){
	}
	
	public GoodsVo getGoods() {
		return shoes;
	}

	public void setGoods(GoodsVo shoes) {
		this.shoes = shoes;
	}

	public List<GoodsPropertiesVo> getGoodsProperties() {
		return shoesProperties;
	}

	public void setGoodsProperties(List<GoodsPropertiesVo> shoesProperties) {
		this.shoesProperties = shoesProperties;
	}

	public boolean isHasProperties() {
		return hasProperties;
	}



	public void setHasProperties(boolean hasProperties) {
		this.hasProperties = hasProperties;
	}



	public String searchGoodsProperties() {
		this.setHasProperties(false);
		String shoesId = (String)SpringFacesUtil.getRequestParameter(EjdConstants.SHOES_ID);
		IGoodsService<Goods,Long> shoesService = (IGoodsService<Goods,Long>)SpringFacesUtil.getSpringBean(SpringBeanConstants.GOODS_SERVICE_BEAN_NAME);
		shoesService.setEntityClass(Goods.class);
		shoesService.setPKClass(Long.class);
		Goods currGoods = shoesService.get(new Long(shoesId));
		BeanCopier copyGoods = BeanCopier.create(Goods.class, GoodsVo.class, false);
		GoodsVo shoesVo = new GoodsVo();
		copyGoods.copy(currGoods, shoesVo, null);
		this.setGoods(shoesVo);
		Set<GoodsProperties> currGoodsProperties = currGoods.getProperties();
		List<GoodsPropertiesVo> pshoesProperties =new ArrayList<GoodsPropertiesVo>();
		if (null !=currGoodsProperties && !(currGoodsProperties.isEmpty())) {
			Iterator<GoodsProperties> iterator = currGoodsProperties.iterator();
			while(iterator.hasNext()) {
				GoodsProperties tempGoodsProperties = iterator.next();
				GoodsPropertiesVo tempGoodsPropertiesVo = new GoodsPropertiesVo();
				BeanCopier copyHere = BeanCopier.create(GoodsProperties.class,GoodsPropertiesVo.class,false);
				copyHere.copy(tempGoodsProperties, tempGoodsPropertiesVo,null);
				pshoesProperties.add(tempGoodsPropertiesVo);
			}
			this.setGoodsProperties(pshoesProperties);
			this.setHasProperties(true);
		} else {
			this.setGoodsProperties(null);
			this.setHasProperties(false);
		}
		return null;
	}
}
